package com.fs.jzzn.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.fs.jzzn.pojo.Expense;
/**
 * @author TiddlerCJ
 */
public interface ExpenseRepository extends JpaRepository<Expense,String>, JpaSpecificationExecutor<Expense>{
	/**
	 * 状态
	 */
	@Transactional
	@Modifying
	@Query(value = "update p_expense p set p.status = ?1,p.msg =?2 where p.id = ?3",nativeQuery = true)
	void check(String status,String msg,String id);
	
	//根据项目查询对应的收入记录
	@Query(value="SELECT p.* FROM p_expense p WHERE p.p_no IN (SELECT t.p_no FROM p_project t WHERE t.contract_no=?1)",nativeQuery=true)
	List<Expense> findBycontractNo(String contractNo);
	
	
	Expense  findByExpenseNo(String expeneNo);
	
	/**
	 * 分页查找我的事务
	 * @param userName
	 * @param pageable
	 * @return
	 */
	//@Query(value="SELECT p.PROC_INST_ID_ as procInstId,p.BUSINESS_KEY_ as businesskey,p.START_TIME_ as startTime,p.START_USER_ID_ as startUser,p.NAME_ as affairTitle,t.NAME_ as status FROM act_hi_procinst p LEFT JOIN act_hi_taskinst t on t.EXECUTION_ID_ =p.ID_   WHERE p.START_USER_ID_ = :userName AND t.END_TIME_ is NULL ",nativeQuery=true)
	//Page<Affair> findAffairByUser(@Param("userName") String userName, Pageable pageable);
}
